<?php
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;

class WelcomeController extends Controller
{
    public function __construct()
    {
        $this->middleware('admin', ['except' => ['register', 'forgot', 'logout']]);
    }

    public function index(Request $request)
    {
        $data['fileupload'] = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : '<font color="red">不支持</font>';
        $data['dbversion'] = DB::select('SELECT VERSION() as dbversion'); //MySQL 版本
        $data['client_ip'] = $request->getClientIp();
        $data['site_protocol'] = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
        return view('admin/welcome', $data);
    }

    public function register()
    {
        return view('admin/register');
    }

    public function forgot()
    {
        return view('admin/forgot');
    }

    public function logout(Request $request)
    {
        Session::forget('token');
        if ($request->ajax()) {
            return response('Unauthorized.', 401);
        } else {
            return redirect('admin');
        }
    }
}
